/*
 * Copyright (c) 2006-2022, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-12-28     unknow       copy by STemwin
 * 2021-12-29     xiangxistu   port for lvgl <lcd_fill_array>
 * 2022-6-26      solar        Improve the api required for resistive touch screen calibration
 */

#include <board.h>
#include "drv_tftlcd.h"
#include "string.h"

#define LOG_TAG "drv.tftlcd"
#include <drv_log.h>

SRAM_HandleTypeDef hsram1;
_tftlcd_data tftlcd_data = {
    0,
    0,
    0,
    0,
};

struct drv_lcd_device
{
    struct rt_device parent;
    struct rt_device_graphic_info lcd_info;
};
static struct drv_lcd_device _lcd;

/*********************************** lcd api ***********************************/
// 写命令
void lcd_write_cmd(uint16_t cmd)
{
    TFTLCD->CMD = cmd;
}

// 写数据
void lcd_write_data(uint16_t data)
{
    TFTLCD->DATA = data;
}

// 写命令数据
void lcd_write_cmd_data(uint16_t cmd, uint16_t data)
{
    lcd_write_cmd(cmd);
    lcd_write_data(data);
}

// 写入颜色
void lcd_write_data_color(uint16_t color)
{
    TFTLCD->DATA = color;
}

// 读数据
uint16_t lcd_read_data(void)
{
    return TFTLCD->DATA;
}

// 设置LCD显示方向
void lcd_set_display_dir(uint8_t dir)
{
    if (dir == 0)     //竖屏
    {
        lcd_write_cmd(0x0001);   
		lcd_write_data(0x0100);
		lcd_write_cmd(0x0003);   //设置彩屏显示方向的寄存器
		lcd_write_data(0x1030);  

		tftlcd_data.height = 320;
		tftlcd_data.width = 240;	
    }
    else //横屏
    {
        lcd_write_cmd(0x0001);   
		lcd_write_data(0x0000);
		lcd_write_cmd(0x0003);   //设置彩屏显示方向的寄存器
		lcd_write_data(0x1038);

		tftlcd_data.height = 240;
		tftlcd_data.width = 320;	
    }
    
    tftlcd_data.dir = dir;
}

// 设置窗口
void lcd_set_window(uint16_t x, uint16_t y, uint16_t width, uint16_t height)
{
    if (tftlcd_data.dir == 0)
    {
        lcd_write_cmd(0x0050);
        lcd_write_data(x);
        lcd_write_cmd(0x0051);  
        lcd_write_data(width);
        lcd_write_cmd(0x0052);   
        lcd_write_data(y);
        lcd_write_cmd(0x0053);   
        lcd_write_data(height);
    
        lcd_write_cmd(0x0020);   
        lcd_write_data(x);
        lcd_write_cmd(0x0021);   
        lcd_write_data(y);
    }
    else 
    {
        lcd_write_cmd(0x0052);   
        lcd_write_data(x);
        lcd_write_cmd(0x0053);  
        lcd_write_data(width);
        lcd_write_cmd(0x0050);   
        lcd_write_data(y);
        lcd_write_cmd(0x0051);   
        lcd_write_data(height);
    
        lcd_write_cmd(0x0021);   
        lcd_write_data(x);
        lcd_write_cmd(0x0020);   
        lcd_write_data(y);	
    }
    lcd_write_cmd(0x0022);
}

// 清屏函数
void lcd_clear(uint16_t color)
{
    uint16_t i = 0, j = 0;

	lcd_set_window(0, 0, tftlcd_data.width-1, tftlcd_data.height-1); // 作用区域
  	for (i = 0; i < tftlcd_data.width; i++)
	{
		for (j = 0; j < tftlcd_data.height; j++)
		{
			lcd_write_data_color(color);
		}
	} 
}

// 矩形填充
void lcd_fill(uint16_t x_start, uint16_t y_start, uint16_t x_end, uint16_t y_end, uint16_t color)
{
    uint16_t temp = 0;

    if ((x_start > x_end) || (y_start > y_end))
    {
        return;
    }   

	lcd_set_window(x_start, y_start, x_end, y_end); 
    x_start = x_end - x_start + 1;
	y_start = y_end - y_start + 1;

	while (x_start--)
	{
	 	temp = y_start;
		while (temp--)
	 	{			
			lcd_write_data_color(color);	
		}
	}
}

// 画点
void lcd_draw_point(uint16_t x, uint16_t y, uint16_t color)
{
    lcd_set_window(x, y, x, y);
    lcd_write_data_color(color);
}

// 读点
uint16_t lcd_read_point(uint16_t x, uint16_t y)
{
    uint16_t r = 0;
	uint16_t r1 = 0, r2 = 0, r3 = 0;
	
	if (x >= tftlcd_data.width || y >= tftlcd_data.height)
    {
        return 0;	//超过了范围,直接返回
    }		     
	lcd_set_window(x, y, x, y);

    lcd_write_cmd(0x0022);
	r = lcd_read_data(); // dummy Read     		 				    
	r = lcd_read_data(); // 实际坐标颜色
	r1 = r & 0xf800;
	r2 = r & 0x07e0;
	r3 = r & 0x001f;

	return (r3 << 11) | ((r2 >> 5) << 5) | (r1 >> 11);
}

// 画线
void lcd_draw_line(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
{
    uint16_t t;
    int xerr = 0, yerr = 0, delta_x, delta_y, distance;
    int incx, incy, urow, ucol;
    delta_x = x2 - x1; // 计算坐标增量
    delta_y = y2 - y1;
    urow = x1;
    ucol = y1;

    if (delta_x > 0)
        incx = 1; // 设置单步方向
    else if (delta_x == 0)
        incx = 0; // 垂直线
    else
    {
        incx = -1;
        delta_x = -delta_x;
    }

    if (delta_y > 0)
        incy = 1;
    else if (delta_y == 0)
        incy = 0; // 水平线
    else
    {
        incy = -1;
        delta_y = -delta_y;
    }

    if (delta_x > delta_y)
        distance = delta_x; // 选取基本增量坐标轴
    else
        distance = delta_y;

    for (t = 0; t <= distance + 1; t++) // 画线输出
    {
        lcd_draw_point(urow, ucol, color);
        xerr += delta_x;
        yerr += delta_y;

        if (xerr > distance)
        {
            xerr -= distance;
            urow += incx;
        }

        if (yerr > distance)
        {
            yerr -= distance;
            ucol += incy;
        }
    }
}

// 画矩形
void lcd_draw_retangle(uint16_t x1, uint16_t y1, uint16_t x2, uint16_t y2, uint16_t color)
{
    lcd_draw_line(x1, y1, x2, y1, color);
    lcd_draw_line(x1, y1, x1, y2, color);
    lcd_draw_line(x1, y2, x2, y2, color);
    lcd_draw_line(x2, y1, x2, y2, color);
}

// 画圆
void lcd_draw_circle(uint16_t x, uint16_t y, uint16_t r, uint16_t color)
{
    int a = 0, b = 0;
	int di = 0;

	b = r;	  
	di = 3 - (r << 1);             //判断下个点位置的标志
	while (a <= b)
	{
		lcd_draw_point(x + a, y - b, color);             //5
 		lcd_draw_point(x + b, y - a, color);             //0           
		lcd_draw_point(x + b, y + a, color);             //4               
		lcd_draw_point(x + a, y + b, color);             //6 
		lcd_draw_point(x - a, y + b, color);             //1       
 		lcd_draw_point(x - b, y + a, color);             
		lcd_draw_point(x - a, y - b, color);             //2             
  		lcd_draw_point(x - b, y - a, color);             //7     	         
		a++;
		//使用Bresenham算法画圆     
		if (di < 0)
        {
            di += (4 * a + 6);
        }	  
		else
		{
			di += (10 + 4 * (a - b));   
			b--;
		} 						    
	}
}

// hal库初始化
void tftlcd_hal_init(void)
{
    __HAL_RCC_GPIOD_CLK_ENABLE();
    __HAL_RCC_GPIOE_CLK_ENABLE();
    __HAL_RCC_GPIOF_CLK_ENABLE();
    __HAL_RCC_GPIOG_CLK_ENABLE();
    __HAL_RCC_GPIOB_CLK_ENABLE();

    FSMC_NORSRAM_TimingTypeDef Timing;

    /** Perform the SRAM1 memory initialization sequence
  */
    hsram1.Instance = FSMC_NORSRAM_DEVICE;
    hsram1.Extended = FSMC_NORSRAM_EXTENDED_DEVICE;
    /* hsram1.Init */
    hsram1.Init.NSBank = FSMC_NORSRAM_BANK4;
    hsram1.Init.DataAddressMux = FSMC_DATA_ADDRESS_MUX_DISABLE;
    hsram1.Init.MemoryType = FSMC_MEMORY_TYPE_SRAM;
    hsram1.Init.MemoryDataWidth = FSMC_NORSRAM_MEM_BUS_WIDTH_16;
    hsram1.Init.BurstAccessMode = FSMC_BURST_ACCESS_MODE_DISABLE;
    hsram1.Init.WaitSignalPolarity = FSMC_WAIT_SIGNAL_POLARITY_LOW;
    hsram1.Init.WrapMode = FSMC_WRAP_MODE_DISABLE;
    hsram1.Init.WaitSignalActive = FSMC_WAIT_TIMING_BEFORE_WS;
    hsram1.Init.WriteOperation = FSMC_WRITE_OPERATION_ENABLE;
    hsram1.Init.WaitSignal = FSMC_WAIT_SIGNAL_DISABLE;
    hsram1.Init.ExtendedMode = FSMC_EXTENDED_MODE_DISABLE;
    hsram1.Init.AsynchronousWait = FSMC_ASYNCHRONOUS_WAIT_DISABLE;
    hsram1.Init.WriteBurst = FSMC_WRITE_BURST_DISABLE;
    hsram1.Init.PageSize = FSMC_PAGE_SIZE_NONE;
    /* Timing */
    Timing.AddressSetupTime = 5;
    Timing.AddressHoldTime = 1;
    Timing.DataSetupTime = 9;
    Timing.BusTurnAroundDuration = 0;
    Timing.CLKDivision = 2;
    Timing.DataLatency = 2;
    Timing.AccessMode = FSMC_ACCESS_MODE_A;
    /* ExtTiming */

    if (HAL_SRAM_Init(&hsram1, &Timing, &Timing) != HAL_OK)
    {
        Error_Handler();
    }
}

// tftlcd硬件初始化
void tftlcd_hardware_init(void)
{
    rt_thread_mdelay(50);
    lcd_write_cmd(0X00);
    tftlcd_data.id = lcd_read_data();
    
    LOG_I(" LCD ID: %x", tftlcd_data.id); //打印LCD ID
    
    lcd_write_cmd(0x00E3);lcd_write_data(0x3008); // Set internal timing
    lcd_write_cmd(0x00E7);lcd_write_data(0x0012); // Set internal timing
    lcd_write_cmd(0x00EF);lcd_write_data(0x1231); // Set internal timing
    lcd_write_cmd(0x0001);lcd_write_data(0x0100); // set SS and SM bit
    lcd_write_cmd(0x0002);lcd_write_data(0x0700); // set 1 line inversion
    lcd_write_cmd(0x0003);lcd_write_data(0x1030); // set GRAM write direction and BGR=1.
    lcd_write_cmd(0x0004);lcd_write_data(0x0000); // Resize register
    lcd_write_cmd(0x0008);lcd_write_data(0x0207); // set the back porch and front porch
    lcd_write_cmd(0x0009);lcd_write_data(0x0000); // set non-display area refresh cycle ISC[3:0]
    lcd_write_cmd(0x000A);lcd_write_data(0x0000); // FMARK function
    lcd_write_cmd(0x000C);lcd_write_data(0x0000); // RGB interface setting
    lcd_write_cmd(0x000D);lcd_write_data(0x0000); // Frame marker Position
    lcd_write_cmd(0x000F);lcd_write_data(0x0000); // RGB interface polarity
    //*************Power On sequence ****************//
    lcd_write_cmd(0x0010);lcd_write_data(0x0000); // SAP);WriteData(BT[3:0]);WriteData(AP);WriteData(DSTB);WriteData(SLP);WriteData(STB
    lcd_write_cmd(0x0011);lcd_write_data(0x0007); // DC1[2:0]);WriteData(DC0[2:0]);WriteData(VC[2:0]
    lcd_write_cmd(0x0012);lcd_write_data(0x0000); // VREG1OUT voltage
    lcd_write_cmd(0x0013);lcd_write_data(0x0000); // VDV[4:0] for VCOM amplitude
    rt_thread_mdelay(20); // Dis-charge capacitor power voltage
    lcd_write_cmd(0x0010);lcd_write_data(0x1490); // SAP);WriteData(BT[3:0]);WriteData(AP);WriteData(DSTB);WriteData(SLP);WriteData(STB
    lcd_write_cmd(0x0011);lcd_write_data(0x0227); // DC1[2:0]);WriteData(DC0[2:0]);WriteData(VC[2:0]
    rt_thread_mdelay(50); // Delay 50ms
    lcd_write_cmd(0x0012);lcd_write_data(0x001C); // Internal reference voltage= Vci;
    rt_thread_mdelay(50); // Delay 50ms
    lcd_write_cmd(0x0013);lcd_write_data(0x1A00); // Set VDV[4:0] for VCOM amplitude
    lcd_write_cmd(0x0029);lcd_write_data(0x0025); // Set VCM[5:0] for VCOMH
    lcd_write_cmd(0x002B);lcd_write_data(0x000C); // Set Frame Rate
    rt_thread_mdelay(50); // Delay 50ms
    lcd_write_cmd(0x0020);lcd_write_data(0x0000); // GRAM horizontal Address
    lcd_write_cmd(0x0021);lcd_write_data(0x0000); // GRAM Vertical Address
    // ----------- Adjust the Gamma Curve ----------//
    lcd_write_cmd(0x0030);lcd_write_data(0x0000);
    lcd_write_cmd(0x0031);lcd_write_data(0x0506);
    lcd_write_cmd(0x0032);lcd_write_data(0x0104);
    lcd_write_cmd(0x0035);lcd_write_data(0x0207);
    lcd_write_cmd(0x0036);lcd_write_data(0x000F);
    lcd_write_cmd(0x0037);lcd_write_data(0x0306);
    lcd_write_cmd(0x0038);lcd_write_data(0x0102);
    lcd_write_cmd(0x0039);lcd_write_data(0x0707);
    lcd_write_cmd(0x003C);lcd_write_data(0x0702);
    lcd_write_cmd(0x003D);lcd_write_data(0x1604);
    //------------------ Set GRAM area ---------------//
    lcd_write_cmd(0x0050);lcd_write_data(0x0000); // Horizontal GRAM Start Address
    lcd_write_cmd(0x0051);lcd_write_data(0x00EF); // Horizontal GRAM End Address
    lcd_write_cmd(0x0052);lcd_write_data(0x0000); // Vertical GRAM Start Address
    lcd_write_cmd(0x0053);lcd_write_data(0x013F); // Vertical GRAM Start Address
    lcd_write_cmd(0x0060);lcd_write_data(0x2700); // Gate Scan Line
    lcd_write_cmd(0x0061);lcd_write_data(0x0001); // NDL,VLE);WriteData(REV
    lcd_write_cmd(0x006A);lcd_write_data(0x0000); // set scrolling line
    //-------------- Partial Display Control ---------//
    lcd_write_cmd(0x0080);lcd_write_data(0x0000);
    lcd_write_cmd(0x0081);lcd_write_data(0x0000);
    lcd_write_cmd(0x0082);lcd_write_data(0x0000);
    lcd_write_cmd(0x0083);lcd_write_data(0x0000);
    lcd_write_cmd(0x0084);lcd_write_data(0x0000);
    lcd_write_cmd(0x0085);lcd_write_data(0x0000);
    //------------ Panel Control -------------------//
    lcd_write_cmd(0x0090);lcd_write_data(0x0010);
    lcd_write_cmd(0x0092);lcd_write_data(0x0600);
    lcd_write_cmd(0x0007);lcd_write_data(0x0133); // 262K color and display ON

    lcd_write_cmd(0x0010);lcd_write_data(0x12B0); // SAP);WriteData(BT[3:0]);WriteData(AP);WriteData(DSTB);WriteData(SLP
    lcd_write_cmd(0x0011);lcd_write_data(0x0007);
    lcd_write_cmd(0x0017);lcd_write_data(0x0001); // DC1[2:0]);WriteData(DC0[2:0]);WriteData(VC[2:0]
    lcd_write_cmd(0x0012);lcd_write_data(0x01BD); // VREG1OUT voltage
    lcd_write_cmd(0x0013);lcd_write_data(0x1700); // VDV[4:0] for VCOM amplitude
    rt_thread_mdelay(20); // Dis-charge capacitor power voltage
    lcd_write_cmd(0x0010);lcd_write_data(0x1490); // SAP);WriteData(BT[3:0]);WriteData(AP);WriteData(DSTB);WriteData(SLP);WriteData(STB
    lcd_write_cmd(0x0011);lcd_write_data(0x0227); // DC1[2:0]);WriteData(DC0[2:0]);WriteData(VC[2:0]
    rt_thread_mdelay(50); // Delay 50ms
    lcd_write_cmd(0x0012);lcd_write_data(0x001C); //Inernal reference voltage =Vci;
    rt_thread_mdelay(50); // Delay 50ms
    lcd_write_cmd(0x0013);lcd_write_data(0x1A00); // VDV[4:0] for VCOM amplitude
    lcd_write_cmd(0x0029);lcd_write_data(0x0025); // VCM[5:0] for VCOMH
    rt_thread_mdelay(50); // Delay 50ms
    //lcd_write_cmd(0x0007);lcd_write_data(0x0133); // 262K color and display ON

    lcd_write_cmd(0x0007);lcd_write_data(0x0133);
    rt_thread_mdelay(120);
    lcd_write_cmd(0x0022);

    lcd_set_display_dir(TFTLCD_DIR);
    lcd_clear(WHITE);
}

/*********************************** dev api ***********************************/
static void set_pixel(const char *pixel, int x, int y)
{
    uint16_t color = 0;

    color = *(uint16_t *)pixel;
    lcd_draw_point(x, y, color);
}

static void get_pixel(char *pixel, int x, int y)
{
    *(uint16_t *)pixel = lcd_read_point(x, y);
}

static void draw_hline(const char *pixel, int x1, int x2, int y)
{
    uint16_t color = 0;

    color = *(uint16_t *)pixel;
    lcd_draw_line(x1, y, x2, y, color);
}

static void draw_vline(const char *pixel, int x, int y1, int y2)
{
    uint16_t color = 0;

    color = *(uint16_t *)pixel;
    lcd_draw_line(x, y1, x, y2, color);
}

static void blit_line(const char *pixel, int x, int y, rt_size_t size)
{
    uint16_t *p = (rt_uint16_t*)pixel;

    lcd_set_window(x, y, tftlcd_data.width-1, tftlcd_data.height-1); // 作用区域;
    for (; size > 0; size--, p++)
        TFTLCD->DATA = *p;
}

struct rt_device_graphic_ops fsmc_lcd_ops = {
    set_pixel,
    get_pixel,
    draw_hline,
    draw_vline,
    blit_line,
};

static rt_err_t drv_lcd_init(struct rt_device *device)
{
    tftlcd_hal_init();
    tftlcd_hardware_init();

    return RT_EOK;
}

static rt_err_t drv_lcd_open(rt_device_t dev, rt_uint16_t oflag)
{


    return RT_EOK;
}
// rt_err_t  (*close)  (rt_device_t dev);
// rt_size_t (*read)   (rt_device_t dev, rt_off_t pos, void *buffer, rt_size_t size);
// rt_size_t (*write)  (rt_device_t dev, rt_off_t pos, const void *buffer, rt_size_t size);

static rt_err_t drv_lcd_control(struct rt_device *device, int cmd, void *args)
{
    struct drv_lcd_device *lcd = (struct drv_lcd_device *)device;
    switch (cmd)
    {
    case RTGRAPHIC_CTRL_GET_INFO:
    {
        struct rt_device_graphic_info *info = (struct rt_device_graphic_info *)args;

        RT_ASSERT(info != RT_NULL);

        //this needs to be replaced by the customer
        info->pixel_format  = lcd->lcd_info.pixel_format;
        info->bits_per_pixel = lcd->lcd_info.bits_per_pixel;
        info->width = tftlcd_data.width;
        info->height = tftlcd_data.height;
    }
    break;
    }

    return RT_EOK;
}

#ifdef RT_USING_DEVICE_OPS
const static struct rt_device_ops lcd_ops = {
    drv_lcd_init,
    drv_lcd_open,
    RT_NULL,
    RT_NULL,
    RT_NULL,
    drv_lcd_control
};
#endif

int drv_lcd_hw_init(void)
{
    rt_err_t result = RT_EOK;
    struct rt_device *device = &_lcd.parent;
    /* memset _lcd to zero */
    memset(&_lcd, 0x00, sizeof(_lcd));

    _lcd.lcd_info.bits_per_pixel = 16;
    _lcd.lcd_info.pixel_format = RTGRAPHIC_PIXEL_FORMAT_RGB565;

    device->type = RT_Device_Class_Graphic;
#ifdef RT_USING_DEVICE_OPS
    device->ops = &lcd_ops;
#else
    device->init = drv_lcd_init;
    device->open = drv_lcd_open;
    device->control = drv_lcd_control;
#endif
    device->user_data = &fsmc_lcd_ops;
    /* register lcd device */
    result = rt_device_register(device, "lcd", RT_DEVICE_FLAG_RDWR | RT_DEVICE_FLAG_STANDALONE);
    if (result != RT_EOK)
    {
        LOG_E("tftlcd register err code: %d", result);
        return result;
    }
    LOG_E("tftlcd register success!\r\n");

    return result;
}
INIT_DEVICE_EXPORT(drv_lcd_hw_init);

//////////////////////////////////////////////////////////////////////////////////////////////////
// #define BSP_USING_ONBOARD_LCD_TEST
#ifdef BSP_USING_ONBOARD_LCD_TEST
#include <stdlib.h> /* atoi */

void lcd_test(int argc, void **argv)
{
    static rt_uint8_t lcd_init = 0;
    rt_device_t lcd = RT_NULL;
    rt_uint16_t color = BLACK;
    rt_uint16_t x1 = 0, y1 = 0, x2 = 0, y2 = 0;
    rt_uint16_t r = 0;
    rt_size_t size = 0;

    struct rt_device_graphic_ops *ops = RT_NULL;

    if (lcd_init == 0)
    {
        lcd_init = 1;

        lcd = rt_device_find("lcd");
        rt_device_init(lcd);

        ops = (struct rt_device_graphic_ops *)lcd->user_data;
        if (ops != RT_NULL)
        {
            if (ops->draw_hline != RT_NULL)
            {
                ops->draw_hline((const char *)&color, 50, 100, 100);
            }
        }
    }

    if (argc == 1 || argc == 2)
    {
        color = WHITE;

        if (argc == 2)
        {
            color = atoi(argv[1]);
        }

        lcd_clear(color);
    }
    else if (argc >= 4)
    {
        if (rt_strcmp(argv[1], "point") == 0)
        {
            x1 = atoi(argv[2]);
            y1 = atoi(argv[3]);

            if (argc == 5)
            {
                color = atoi(argv[4]);
            }

            lcd_draw_point(x1, y1, color);
        }
        else if (rt_strcmp(argv[1], "line") == 0)
        {
            x1 = atoi(argv[2]);
            y1 = atoi(argv[3]);
            x2 = atoi(argv[4]);
            y2 = atoi(argv[5]);

            if (argc == 7)
            {
                color = atoi(argv[6]);
            }

            lcd_draw_line(x1, y1, x2, y2, color);
        }
        else if (rt_strcmp(argv[1], "blit") == 0)
        {
            x1 = atoi(argv[2]);
            y1 = atoi(argv[3]);
            size = atoi(argv[4]);

            if (argc == 6)
            {
                color = atoi(argv[5]);
            }

            lcd_draw_blit_line(x1, y1,size, color);
        }
        else if (rt_strcmp(argv[1], "retangle") == 0)
        {
            x1 = atoi(argv[2]);
            y1 = atoi(argv[3]);
            x2 = atoi(argv[4]);
            y2 = atoi(argv[5]);

            if (argc == 7)
            {
                color = atoi(argv[6]);
            }

            lcd_draw_retangle(x1, y1, x2, y2, color);
        }
        else if (rt_strcmp(argv[1], "fill") == 0)
        {
            x1 = atoi(argv[2]);
            y1 = atoi(argv[3]);
            x2 = atoi(argv[4]);
            y2 = atoi(argv[5]);

            if (argc == 7)
            {
                color = atoi(argv[6]);
            }

            lcd_fill(x1, y1, x2, y2, color);
        }
        else if (rt_strcmp(argv[1], "circle") == 0)
        {
            x1 = atoi(argv[2]);
            y1 = atoi(argv[3]);
            r = atoi(argv[4]);

            if (argc == 6)
            {
                color = atoi(argv[5]);
            }

            lcd_draw_circle(x1, y1, r, color);
        }
    }
}
MSH_CMD_EXPORT(lcd_test, lcd test for mcu lcd);
#endif

